/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package View;
import Model.Action;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Image;
import java.io.File;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;

/**
 *
 * @author Randy
 */
public class CustomCellRenderer implements ListCellRenderer {
    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
    public Component getListCellRendererComponent(JList list, Object value, int index,
      boolean isSelected, boolean cellHasFocus) {
        Action item = (Action)value;
        String soundPath = item.getSoundPath();
        String folder = "\\Carpeta Maestra\\Simbolos\\";
        String audiosFolder = "\\Carpeta Maestra\\Audios\\";
        String basePath = new File("").getAbsolutePath();
        JPanel renderer = new JPanel();
        renderer.setBackground(Color.WHITE);
        JLabel mini = new JLabel();
        JLabel action = new JLabel();
        String movementType = item.getMovementType();

        
        
        JLabel quantity = new JLabel(String.valueOf(item.getdX()));
        JLabel soundLbl = new JLabel(soundPath);
        soundLbl.setToolTipText(soundPath);
        
        String pathToUse = "";
        if (movementType.equals("Voltear"))
           {
               quantity.setVisible(false);
               soundLbl.setVisible(false);
                
           }else if (soundPath.equals(""))
        {  
            pathToUse = basePath + folder + item.getdX() + ".png";
            quantity.setVisible(true);
            soundLbl.setVisible(false);
        }
        else
        {
             quantity.setVisible(false);
            soundLbl.setVisible(true);
            pathToUse = basePath + audiosFolder + soundPath;
            
         }       
        ImageIcon miniImageIcon = new ImageIcon(item.getactorType());
        ImageIcon actionImageIcon = new ImageIcon(basePath +folder+item.getImagePath()+".png");
        
       
            
        
        ImageIcon quantityImageIcon = new ImageIcon(pathToUse);
        
                
        Image miniImage = miniImageIcon.getImage(); // transform it 
        Image actionImage = actionImageIcon.getImage(); // transform it 
        Image quantityImage = quantityImageIcon.getImage(); // transform it 
        miniImage = miniImage.getScaledInstance(40, 40,  java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
        actionImage = actionImage.getScaledInstance(40, 40,  java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
        miniImageIcon = new ImageIcon(miniImage);  // transform it back
        quantityImageIcon = new ImageIcon(quantityImage);  // transform it back
        actionImageIcon = new ImageIcon(actionImage);  // transform it back
        mini.setIcon(miniImageIcon);
        action.setIcon(actionImageIcon);
        quantity.setIcon(quantityImageIcon);
        renderer.add(mini);
        renderer.add(action);
        renderer.add(quantity);
        renderer.setEnabled(true);
        if (isSelected) {
            renderer.setBackground(Color.YELLOW);
        }
    return renderer;
  }
}